﻿@{
    Bundle("jquery_validate");
    Bundle("jquery_timepicker");
}

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('@ID("#form")').validate({
            rules: {
                catalogItemID: {
                    required: true,
                    digits: true
                },
                sellerName: {
                    required: true
                },
                sku: {
                    required: true
                }
            }
        });
        jQuery('@ID("#txt_seller")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Seller")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_seller")').val(ui.item.id);
            }
        });
        jQuery('@ID("#txt_catalogItem")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Item").Area("Catalog")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_catalogItem")').val(ui.item.id);
            }
        });
        jQuery('@ID("#txt_available_from")').datetimepicker();
        jQuery('@ID("#txt_available_to")').datetimepicker();
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Update").Ctrl("SalesItem"))" method="post">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>#</label>
            </td>
            <td>
                <input type="text" readonly name="id" value="@JDM.Int32(Model.EntityID)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>&#10001;</label>
            </td>
            <td>
                <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.CreatedOn))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>&#10002;</label>
            </td>
            <td>
                <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.UpdatedOn))" />
            </td>
        </tr>
        <tr>
            <td>
                <a href="@Url.Action(Loc.Act("Edit").Ctrl("Seller").Set(new
                {
                    id = JDM.Int32(Model.Seller.EntityID)
                }))" class="ui-icon ui-icon-extlink"></a>
                <label>@T(Res.Name("Seller"))</label>
            </td>
            <td>
                <input id="@ID("hidden_seller")" type="hidden" name="sellerID" value="@JDM.Int32(Model.Seller.EntityID)" />
                <input id="@ID("txt_seller")" type="text" name="sellerName" value="@JDM.String(Model.Seller.Account.Email)" />
            </td>
        </tr>
        <tr>
            <td>
                <a href="@Url.Action(Loc.Act("Edit").Ctrl("Item").Area("Catalog"))" class="ui-icon ui-icon-extlink"></a>
                <label>@T(Res.Name("CatalogItem"))</label>
            </td>
            <td>
                <input id="@ID("hidden_catalogItem")" type="hidden" name="catalogItemID" value="@JDM.Int32(Model.CatalogItem.EntityID)" />
                @{
                    var t_catItem = (Model.CatalogItem.Translations as IEnumerable<dynamic>)
                        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                            JDM.Int32(Svc.Localization.Language.EntityID));
                    <input id="@ID("txt_catalogItem")" type="text" name="catalogItemName" value="@(t_catItem != null ? JDM.String(t_catItem.Name) : String.Empty)" />
                }
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("Common").Of("Vocab").Name("SKU"))</label>
            </td>
            <td>
                <input type="text" name="sku" value="@JDM.String(Model.SKU)" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Price"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input class="required" type="text" name="price" value="@Svc.Price((decimal)JDM.Decimal(Model.Price))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("AvailableFrom"))</label>
            </td>
            <td>
                <input id="@ID("txt_available_from")" type="text" name="availableFrom" value="@Svc.DateTime((DateTime)JDM.DateTime(Model.AvailableFrom))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("AvailableTo"))</label>
            </td>
            <td>
                <input id="@ID("txt_available_to")" type="text" name="availableTo" value="@Svc.DateTime((DateTime)JDM.DateTime(Model.AvailableTo))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("SalesItemFlags").Name("Active"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="Active" @(JDM.HasFlags(Model.Flags, "Active") ? "checked" : String.Empty) />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("SalesItemFlags").Name("VariablePricing"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="VariablePricing" @(JDM.HasFlags(Model.Flags, "VariablePricing") ? "checked" : String.Empty) />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>